package ptaTest7;

import java.util.Scanner;

class Repo {
	@SuppressWarnings("unused")
	private String items;
	private String[] task;
	private static int i = 0;
	private boolean flag = true;

	public Repo(String items) {
		this.items = items;
		task = items.split(" ");
	}

	public int getSize() {
		return task.length - i;
	}

	public synchronized void run1() {
		while (!flag) {
			try {
				wait();
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		if (getSize() > 0) {
			flag = false;
			System.out.println(Thread.currentThread().getName() + " finish " + task[i++]);
			notify();
		}
	}

	public synchronized void run2() {
		while (flag) {
			try {
				wait();
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		if (getSize() > 0) {
			flag = true;
			System.out.println(Thread.currentThread().getName() + " finish " + task[i++]);
			notify();
		}
	}

}

class Worker1 implements Runnable {
	private Repo repo;

	public Worker1(Repo repo) {
		this.repo = repo;
	}

	@Override
	public void run() {
		while (repo.getSize()!=0)
			repo.run1();
	}

}

class Worker2 implements Runnable {
	private Repo repo;

	public Worker2(Repo repo) {
		this.repo = repo;
	}

	@Override
	public void run() {
		while (repo.getSize()!=0)
			repo.run2();
	}
}
public class Test746 {
    public static void main(String[] args) throws InterruptedException {
        Scanner sc = new Scanner(System.in);
        Repo repo = new Repo(sc.nextLine());
        Thread t1 = new Thread(new Worker1(repo));
        Thread t2 = new Thread(new Worker2(repo));
        t1.start();
        Thread.yield();
        t2.start();
        sc.close();
    }
}